#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class Solution:
    """
    A has enough space
    A有足够的空间
    """
    def mergeSortedArray(self, A, m, B, n):
        # 倒序插入
        remain_m, remain_n = m, n
        while remain_m > 0 and remain_n > 0:
            a_v, b_v = A[remain_m - 1], B[remain_n - 1]
            if a_v > b_v:
                # print('not ')
                A[remain_m + remain_n - 1] = a_v
                remain_m -= 1
            else:
                # print(remain_m + remain_n - 1)
                A[remain_m + remain_n - 1] = b_v
                remain_n -= 1

        A[0:remain_n] = B[0:remain_n]


def main():
    print("start main")
    s = Solution()
    A = [1, 2, 3, None, None]
    B = [4, 5]

    s.mergeSortedArray(A, 3, B, 2)
    print(A)

if __name__ == "__main__":
    main()
